package com.woniu.ly.manageassembly.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.ly.model.model.Tour;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface TourMapper extends BaseMapper<Tour> {
    @Update("UPDATE t_tour SET tour_status = #{status}, tour_end_time = CURRENT_TIMESTAMP WHERE tour_id = #{tourId}")
    void changeTourStatus(@Param("tourId") int tourId,@Param("status") String status);

    @Update("UPDATE t_tour SET guide_id = #{guideId} WHERE tour_id = #{tourId}")
    void chooseGuide(@Param("guideId") int guideId,@Param("tourId") int tourId);

    @Select("<script>" +
            "SELECT tour_id,tour_price,tour_type,product_id,tour_start_time,tour_max_num,tour_now_num,guide_id,tour_status,tour_end_time FROM `t_tour`" +
            "<where>" +
            "<if test='tourId>0'>" +
            "and tour_id = #{tourId}" +
            "</if>" +
            "<if test='tourType!=null'>" +
            " and tour_type = #{tourType}" +
            "</if>" +
            "<if test='productId>0'>" +
            " and product_id = #{productId}" +
            "</if>" +
            "<if test='tourStatus!=null'>" +
            " and tour_status = #{tourStatus}" +
            "</if>" +
            "</where>" +
            "</script>")
    IPage<Tour> getTours(Page<Tour> page
            ,@Param("tourId") int tourId
            ,@Param("tourType") String tourType
            ,@Param("productId") int productId
            ,@Param("tourStatus") String tourStatus);
}
